package com.genersoft.iot.vmp.storager.dao;

import com.genersoft.iot.vmp.storager.dao.dto.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface UserMapper {

    @Insert("INSERT INTO users (id,username, password, role_id, create_time) VALUES" +
            "(seq_user.nextval,'${username}', '${password}', '${roleId}', sysdate")
    int add(User user);

    @Update("UPDATE users " +
            "SET username=#{username}, " +
            "password=#{password}, " +
            "role_id=#{roleId} " +
            "WHERE id=#{id}")
    int update(User user);

    @Delete("DELETE FROM users WHERE app=#{app} AND id=#{id}")
    int delete(User user);

    @Select("select * FROM users WHERE username=#{username} AND password=#{password}")
    @ResultMap("user")
    User select(String username, String password);

    @Select("select * FROM users WHERE id=#{id}")
    @ResultMap("user")
    User selectById(int id);

    @Select("select * FROM users WHERE username=#{username}")
    @Results(id="user",
    value = { 
       @Result(property = "id", column = "id"), @Result(property = "username", column = "username"), 
       @Result(property = "password", column = "password"), @Result(property = "roleId", column = "role_id"), 
       @Result(property = "createTime", column = "create_time"), 
       })
    User getUserByUsername(String username);
}
